package com.gxa.dr2.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.dr2.dto.LayDTO;
import com.gxa.dr2.dto.Response;
import com.gxa.dr2.mapper.KeyDao;
import com.gxa.dr2.param.MyParam;
import com.gxa.dr2.pojo.Key;
import com.gxa.dr2.pojo.SalePerformance;
import com.gxa.dr2.service.KeyService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class KeyServiceImpl implements KeyService {
    @Resource
    private KeyDao keyDao;
    @Override
    public int deleteByPrimaryKey(Integer keyId) {
        return keyDao.deleteByPrimaryKey(keyId);
    }

    @Override
    public int insert(Key record) {
        return keyDao.insert(record);
    }

    @Override
    public int insertSelective(Key record) {
        return keyDao.insertSelective(record);
    }

    @Override
    public Key selectByPrimaryKey(Integer keyId) {
        return keyDao.selectByPrimaryKey(keyId);
    }

    @Override
    public int updateByPrimaryKeySelective(Key record) {
        return keyDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Key record) {
        return keyDao.updateByPrimaryKey(record);
    }

    public int deleteByIds(Integer[] ids) {
        for (Integer id:
                ids) {
            keyDao.deleteByPrimaryKey(id);
        }
        return 1;
    }

    @Override
    public LayDTO list(MyParam param) {
        // 分页
        PageHelper.startPage(param.getPage(), param.getLimit());
        List<Key> Keys = keyDao.findByParam(param);
        // 将结果集包装成pageInfo
        PageInfo<Key> pageInfo = new PageInfo<>(Keys);
        return Response.success(pageInfo.getTotal(), pageInfo.getList());
    }


}
